package sg.edu.nus.iss.billing.controller;

/**
 * @author sammil
 * 
 */

import java.math.BigDecimal;

import sg.edu.nus.iss.billing.entity.RecordState;
import sg.edu.nus.iss.billing.entity.service.CableTVService;
import sg.edu.nus.iss.billing.entity.service.DigitalVoiceService;
import sg.edu.nus.iss.billing.entity.service.MobileVoiceService;
import sg.edu.nus.iss.billing.entity.service.RateUnit;
import sg.edu.nus.iss.billing.entity.service.RateVAService;
import sg.edu.nus.iss.billing.entity.service.ValueAddedService;
import sg.edu.nus.iss.billing.entity.service.ValueAddedService.ServiceType;
import sg.edu.nus.iss.billing.entity.transaction.CallType;
import sg.edu.nus.iss.billing.exception.ControllerException;

public class MasterServiceLoader {
	
	public static void main(String s[]){
		try {
			MasterServiceLoader.loadServices();
		} catch (ControllerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	static String mobileServices[][] = {
			{ "MV001", "PowerValue 300", "25.00", "" },
			{ "MV002", "PowerValue 500", "50.00", "" } };
	
	static Object mobileVAS[][] = {
		{"MV001","Local Call",CallType.LOCAL, "5",RateUnit.SECOND, "0.08",RecordState.ACTIVE, ServiceType.BASIC},
		{"MV002","Local Call",CallType.LOCAL, "0",RateUnit.SECOND, "0.04",RecordState.ACTIVE, ServiceType.BASIC},
		{"MV001","IDD",CallType.IDD, "5",RateUnit.SECOND, "0.30",RecordState.ACTIVE,ServiceType.ADDTIONAL},
		{"MV002","IDD",CallType.IDD, "5",RateUnit.SECOND, "0.20",RecordState.ACTIVE, ServiceType.ADDTIONAL},
		{"MV001","Roaming",CallType.ROAMING, "5",RateUnit.SECOND, "0.30",RecordState.ACTIVE,ServiceType.ADDTIONAL},
		{"MV002","Roaming",CallType.ROAMING, "0",RateUnit.SECOND, "0.10",RecordState.ACTIVE, ServiceType.ADDTIONAL}
	};

	static String ditigalServices[][] = {
			{ "DV001", "Digital Home 300", "15.00", "", "30.00" },
			{ "DV002", "Digital Home 500", "20.00", "", "20.00" } };
	
	static Object ditigalVAS[][] = {
		{"DV001","Local Call",CallType.LOCAL, "5",RateUnit.SECOND, "0.08",RecordState.ACTIVE, ServiceType.BASIC},
		{"DV002","Local Call",CallType.LOCAL, "0",RateUnit.SECOND, "0.04",RecordState.ACTIVE, ServiceType.BASIC},
		{"DV001","IDD",CallType.IDD, "5",RateUnit.SECOND, "0.30",RecordState.ACTIVE,ServiceType.ADDTIONAL},
		{"DV002","IDD",CallType.IDD, "5",RateUnit.SECOND, "0.20",RecordState.ACTIVE, ServiceType.ADDTIONAL}
	};

	static String cableServices[][] = {
			{ "CT001", "BASIC 3", "15.00", "35.00" },
			{ "CT002", "BASIC 5", "25.00", "30.00" } };
	
	static Object cableVas[][] = {
		{ "CT001", "BBC", "0.0", ServiceType.BASIC },
		{ "CT002", "BBC", "0.0", ServiceType.BASIC },
		{ "CT001", "ABC", "0.0", ServiceType.BASIC },
		{ "CT002", "NBC", "0.0", ServiceType.BASIC },
		{ "CT001", "Discovery", "5", ServiceType.BASIC },
		{ "CT002", "Discovery", "5", ServiceType.BASIC },
		{ "CT001", "NHK", "8", ServiceType.BASIC },
		{ "CT002", "NHK", "8", ServiceType.BASIC },
		{ "CT001", "Star-Movie", "5.0", ServiceType.BOTH },
		{ "CT002", "Star-Movie", "0.0", ServiceType.BASIC },
		{ "CT001", "MTV", "5", ServiceType.ADDTIONAL },
		{ "CT002", "MTV", "3", ServiceType.ADDTIONAL  },
		{ "CT001", "Star-Sports", "5", ServiceType.ADDTIONAL  },
		{ "CT002", "Star-Sports", "3", ServiceType.ADDTIONAL  },
		{ "CT002", "CCTV-4", "3", ServiceType.ADDTIONAL  }
		};

	public static void loadServices() throws ControllerException {

		ServiceController serviceController = new ServiceController();

		/*
		 * WE need removeAll(ObjectType) in Controller or need to check if
		 * services all loaded into the file
		 */

		serviceController.deleteAllServices();

		for (int i = 0; i < mobileServices.length; i++) {
			MobileVoiceService mobileVoiceService = new MobileVoiceService(
					mobileServices[i][0], mobileServices[i][1], new BigDecimal(
							mobileServices[i][2]), RecordState.ACTIVE);
			mobileVoiceService.setRateUnit(RateUnit.SECOND);
//			mobileVoiceService.setServiceRate(new BigDecimal(
//					mobileServices[i][3]));

			serviceController.addService(mobileVoiceService);
		}

		for (int i = 0; i < ditigalServices.length; i++) {
			DigitalVoiceService digitalVoiceService = new DigitalVoiceService(
					ditigalServices[i][0], ditigalServices[i][1],
					new BigDecimal(ditigalServices[i][2]), RecordState.ACTIVE);
			digitalVoiceService.setRateUnit(RateUnit.SECOND);
//			digitalVoiceService.setServiceRate(new BigDecimal(
//					ditigalServices[i][3]));
			digitalVoiceService.setInstallationCharges(new BigDecimal(
					ditigalServices[i][4]));
			serviceController.addService(digitalVoiceService);
		}

		for (int i = 0; i < cableServices.length; i++) {
			CableTVService cableTVService = new CableTVService(
					cableServices[i][0], cableServices[i][1], new BigDecimal(
							cableServices[i][2]), RecordState.ACTIVE);

			cableTVService.setInstallationCharges(new BigDecimal(
					cableServices[i][3]));
			
			if(cableServices[i][1].equals("BASIC 3")){
				cableTVService.setBasicSvcChoiceCount(3);
			} else if(cableServices[i][1].equals("BASIC 5")){
				cableTVService.setBasicSvcChoiceCount(5);
			} else {}
			serviceController.addService(cableTVService);
		}
		
		for (int i = 0; i < mobileVAS.length; i++) {
			RateVAService rvas = new RateVAService(
					mobileVAS[i][0].toString(), mobileVAS[i][1].toString(),(CallType)mobileVAS[i][2], new BigDecimal(
							mobileVAS[i][3].toString()), (RateUnit)mobileVAS[i][4],new BigDecimal(mobileVAS[i][5].toString()), (RecordState) mobileVAS[i][6]);
			rvas.setType((ServiceType) mobileVAS[i][7]);

			serviceController.addVAService(rvas);
		}
		
		
		for (int i = 0; i < ditigalVAS.length; i++) {
			RateVAService rvas = new RateVAService(
					ditigalVAS[i][0].toString(), ditigalVAS[i][1].toString(),(CallType)ditigalVAS[i][2], new BigDecimal(
							ditigalVAS[i][3].toString()), (RateUnit)ditigalVAS[i][4],new BigDecimal(ditigalVAS[i][5].toString()), (RecordState) ditigalVAS[i][6]);
			rvas.setType((ServiceType) mobileVAS[i][7]);
			serviceController.addVAService(rvas);
		}
		
		//add data line
		{
			ValueAddedService lineSvc = new ValueAddedService("DV001", "Data Line", new BigDecimal(30.0));
			lineSvc.setActive(RecordState.ACTIVE);
			lineSvc.setType(ServiceType.ADDTIONAL);
			serviceController.addVAService(lineSvc);
			
			lineSvc = new ValueAddedService("DV002", "Data Line", new BigDecimal(40.0));
			lineSvc.setActive(RecordState.ACTIVE);
			lineSvc.setType(ServiceType.ADDTIONAL);
			serviceController.addVAService(lineSvc);
		}
		
		for (int i = 0; i < cableVas.length; i++) {
			ValueAddedService channelSvc = new ValueAddedService(
					cableVas[i][0].toString(), cableVas[i][1].toString(), new BigDecimal(
							cableVas[i][2].toString()));
			channelSvc.setActive(RecordState.ACTIVE);
			channelSvc.setType((ServiceType) cableVas[i][3]);
			serviceController.addVAService(channelSvc);
		}

	}
}
